package logic

import (
	"context"
	"gorm.io/gorm"
	"healthzy3/model/mysql"

	"healthzy3/healthzy3rpc/healthzy3rpc"
	"healthzy3/healthzy3rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *healthzy3rpc.AddRequest) (*healthzy3rpc.AddResponse, error) {
	// todo: add your logic here and delete this line
	Add := mysql.Health{
		Model:   gorm.Model{},
		Name:    in.Name,
		Status:  in.Status,
		IdCard:  in.IdCard,
		Address: in.Address,
		Cater:   in.Cater,
		Type:    in.Type,
		Doctor:  in.Doctor,
		Price:   int(in.Price),
	}
	err := mysql.DB.Debug().Model(&Add).Create(&Add).Error
	if err != nil {
		panic("数据添加失败")
	}
	return &healthzy3rpc.AddResponse{Id: int64(Add.ID)}, nil
}
